package FE;



import java.io.FileNotFoundException;
import java.io.PrintWriter;

import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ObjectNotActive;
import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

import common.CommonTools;


public class FE_corba {

public static void main(String[] args) {
	
	
	ORB orb = ORB.init(args, null);

		try {
			// what's the need for using narrow?
			POA rootPOA = POAHelper.narrow(orb
					.resolve_initial_references("RootPOA"));

			FEImpl FE = new FEImpl();

			byte[] id = rootPOA.activate_object(FE);
			org.omg.CORBA.Object FE_ref = rootPOA.id_to_reference(id);
			String FE_ior = orb.object_to_string(FE_ref);
			System.out.println(FE_ior);
			PrintWriter file = new PrintWriter(CommonTools.getIORFileName("frontend", "frontend.properties", "frontend"));
			
			file.println(FE_ior);
			file.close();

			/*CommonTools.writeLog("server", "frontend",
					" CORBA Front end server started : ", true);*/

			rootPOA.the_POAManager().activate();

			orb.run();

		} catch (InvalidName e) {
			e.printStackTrace();
		} catch (ServantAlreadyActive e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WrongPolicy e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ObjectNotActive e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AdapterInactive e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
